package main

import (
	"flag"
	"fmt"
	"iron_man_comm/src/common/log"
	"iron_man_comm/src/communication_tool/websocket"
	"os"
	"time"
)

const VERSION = "1.0"

/**
 * @brief:    通信工具
 */
func main() {
	initLog()

	port := flag.Int("port", 9090, "ws port")

	log.Info("------------------ start run, version: %s, port: %d ----------------------", VERSION, *port)
	wsServer := websocket.IotServer{}
	err := wsServer.StartServer(*port)
	if err != nil {
		log.Error("start fail, err: %s", err.Error())
		return
	}
	defer wsServer.Release()

	c := make(chan os.Signal, 1)
	_ = <-c
}
func initLog() {
	err := log.InitLogger(log.LogConfigs{
		LogLevel:          "debug",             // 输出日志级别 "debug" "info" "warn" "error"
		LogFormat:         "logfmt",            // 输出日志格式 logfmt, json
		LogPath:           "./log/debug_tool/", // 输出日志文件位置
		LogFileName:       "run.log",           // 输出日志文件名称
		LogSplitTime:      time.Hour * 24,
		LogFileMaxBackups: 10,                  // 输出最大日志备份个数
		LogMaxAge:         time.Hour * 24 * 30, // 日志保留时间，单位: 天 (day)
		LogStdout:         true,                // 是否输出到控制台
	})
	if err != nil {
		fmt.Println("init log fail, error: %s", err.Error())
		return
	}
}
